/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('abfs', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateBackFlowRequest {
  odpsPartition?: string(name='odpsPartition'),
  timestamp?: string(name='timestamp'),
}

model CreateBackFlowResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model CreateBackFlowResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateBackFlowResponseBody(name='body'),
}

async function createBackFlow(tableName: string, instanceId: string, request: CreateBackFlowRequest): CreateBackFlowResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return createBackFlowWithOptions(tableName, instanceId, request, headers, runtime);
}

async function createBackFlowWithOptions(tableName: string, instanceId: string, request: CreateBackFlowRequest, headers: map[string]string, runtime: Util.RuntimeOptions): CreateBackFlowResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.odpsPartition)) {
    body['odpsPartition'] = request.odpsPartition;
  }
  if (!Util.isUnset(request.timestamp)) {
    body['timestamp'] = request.timestamp;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CreateBackFlow',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/tables/${OpenApiUtil.getEncodeParam(tableName)}/backflows`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model CreateInstanceTableRequest {
  description?: string(name='description'),
  fieldMap?: {
    fields?: [ 
      {
        defaultValue?: string(name='defaultValue'),
        description?: string(name='description'),
        isMultiValue?: boolean(name='isMultiValue'),
        isVirtual?: boolean(name='isVirtual'),
        onlineStatus?: boolean(name='onlineStatus'),
        pkey?: boolean(name='pkey'),
        pluginName?: string(name='pluginName'),
        pluginParam?: string(name='pluginParam'),
        seperator?: string(name='seperator'),
        sourceName?: string(name='sourceName'),
        sourceType?: string(name='sourceType'),
        targetName?: string(name='targetName'),
        targetType?: string(name='targetType'),
      }
    ](name='fields'),
    indexs?: [ 
      {
        field?: string(name='field'),
        indexName?: string(name='indexName'),
      }
    ](name='indexs'),
    isAttributePack?: boolean(name='isAttributePack'),
    maxSkeyNum?: long(name='maxSkeyNum'),
    offlineBuildProtectionThreshold?: long(name='offlineBuildProtectionThreshold'),
    pkey?: string(name='pkey'),
    recordType?: string(name='recordType'),
  }(name='fieldMap'),
  fullDataSourceConfig?: {
    odpsDataDesc?: {
      project?: string(name='project'),
      table?: string(name='table'),
    }(name='odpsDataDesc'),
    type?: string(name='type'),
  }(name='fullDataSourceConfig'),
  incDataSourceConfig?: {
    swiftDataDesc?: {
      topic?: string(name='topic'),
    }(name='swiftDataDesc'),
    type?: string(name='type'),
  }(name='incDataSourceConfig'),
  indexType?: string(name='indexType'),
  tableName?: string(name='tableName'),
  triggerMode?: string(name='triggerMode'),
  ttl?: long(name='ttl'),
}

model CreateInstanceTableResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model CreateInstanceTableResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateInstanceTableResponseBody(name='body'),
}

async function createInstanceTable(instanceId: string, request: CreateInstanceTableRequest): CreateInstanceTableResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return createInstanceTableWithOptions(instanceId, request, headers, runtime);
}

async function createInstanceTableWithOptions(instanceId: string, request: CreateInstanceTableRequest, headers: map[string]string, runtime: Util.RuntimeOptions): CreateInstanceTableResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.description)) {
    body['description'] = request.description;
  }
  if (!Util.isUnset(request.fieldMap)) {
    body['fieldMap'] = request.fieldMap;
  }
  if (!Util.isUnset(request.fullDataSourceConfig)) {
    body['fullDataSourceConfig'] = request.fullDataSourceConfig;
  }
  if (!Util.isUnset(request.incDataSourceConfig)) {
    body['incDataSourceConfig'] = request.incDataSourceConfig;
  }
  if (!Util.isUnset(request.indexType)) {
    body['indexType'] = request.indexType;
  }
  if (!Util.isUnset(request.tableName)) {
    body['tableName'] = request.tableName;
  }
  if (!Util.isUnset(request.triggerMode)) {
    body['triggerMode'] = request.triggerMode;
  }
  if (!Util.isUnset(request.ttl)) {
    body['ttl'] = request.ttl;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CreateInstanceTable',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/tables`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model DeleteInstanceTableResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model DeleteInstanceTableResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DeleteInstanceTableResponseBody(name='body'),
}

async function deleteInstanceTable(tableName: string, instanceId: string): DeleteInstanceTableResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return deleteInstanceTableWithOptions(tableName, instanceId, headers, runtime);
}

async function deleteInstanceTableWithOptions(tableName: string, instanceId: string, headers: map[string]string, runtime: Util.RuntimeOptions): DeleteInstanceTableResponse {
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
  };
  var params = new OpenApi.Params{
    action = 'DeleteInstanceTable',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/tables/${OpenApiUtil.getEncodeParam(tableName)}`,
    method = 'DELETE',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model GetBackFlowResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model GetBackFlowResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetBackFlowResponseBody(name='body'),
}

async function getBackFlow(tableName: string, instanceId: string, id: string): GetBackFlowResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getBackFlowWithOptions(tableName, instanceId, id, headers, runtime);
}

async function getBackFlowWithOptions(tableName: string, instanceId: string, id: string, headers: map[string]string, runtime: Util.RuntimeOptions): GetBackFlowResponse {
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
  };
  var params = new OpenApi.Params{
    action = 'GetBackFlow',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/tables/${OpenApiUtil.getEncodeParam(tableName)}/backflows/${OpenApiUtil.getEncodeParam(id)}`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model GetIndexesResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model GetIndexesResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetIndexesResponseBody(name='body'),
}

async function getIndexes(instanceId: string): GetIndexesResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getIndexesWithOptions(instanceId, headers, runtime);
}

async function getIndexesWithOptions(instanceId: string, headers: map[string]string, runtime: Util.RuntimeOptions): GetIndexesResponse {
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
  };
  var params = new OpenApi.Params{
    action = 'GetIndexes',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/indexes`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model GetInstanceResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model GetInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetInstanceResponseBody(name='body'),
}

async function getInstance(instanceId: string): GetInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getInstanceWithOptions(instanceId, headers, runtime);
}

async function getInstanceWithOptions(instanceId: string, headers: map[string]string, runtime: Util.RuntimeOptions): GetInstanceResponse {
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
  };
  var params = new OpenApi.Params{
    action = 'GetInstance',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model GetInstanceTableResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model GetInstanceTableResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetInstanceTableResponseBody(name='body'),
}

async function getInstanceTable(instanceId: string, tableName: string): GetInstanceTableResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getInstanceTableWithOptions(instanceId, tableName, headers, runtime);
}

async function getInstanceTableWithOptions(instanceId: string, tableName: string, headers: map[string]string, runtime: Util.RuntimeOptions): GetInstanceTableResponse {
  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
  };
  var params = new OpenApi.Params{
    action = 'GetInstanceTable',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/tables/${OpenApiUtil.getEncodeParam(tableName)}`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model ListBackFlowsRequest {
  limit?: long(name='limit'),
}

model ListBackFlowsResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: [  map[string]any ](name='result'),
}

model ListBackFlowsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ListBackFlowsResponseBody(name='body'),
}

async function listBackFlows(tableName: string, instanceId: string, request: ListBackFlowsRequest): ListBackFlowsResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return listBackFlowsWithOptions(tableName, instanceId, request, headers, runtime);
}

async function listBackFlowsWithOptions(tableName: string, instanceId: string, request: ListBackFlowsRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ListBackFlowsResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.limit)) {
    query['limit'] = request.limit;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListBackFlows',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/tables/${OpenApiUtil.getEncodeParam(tableName)}/backflows`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model ListInstanceTableRequest {
  pageNumber?: long(name='PageNumber'),
  pageSize?: long(name='pageSize'),
}

model ListInstanceTableResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model ListInstanceTableResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ListInstanceTableResponseBody(name='body'),
}

async function listInstanceTable(instanceId: string, request: ListInstanceTableRequest): ListInstanceTableResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return listInstanceTableWithOptions(instanceId, request, headers, runtime);
}

async function listInstanceTableWithOptions(instanceId: string, request: ListInstanceTableRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ListInstanceTableResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['pageSize'] = request.pageSize;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListInstanceTable',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/tables`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model ListInstancesRequest {
  pageNumber?: long(name='PageNumber'),
  pageSize?: long(name='pageSize'),
}

model ListInstancesResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model ListInstancesResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ListInstancesResponseBody(name='body'),
}

async function listInstances(request: ListInstancesRequest): ListInstancesResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return listInstancesWithOptions(request, headers, runtime);
}

async function listInstancesWithOptions(request: ListInstancesRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ListInstancesResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['pageSize'] = request.pageSize;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListInstances',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model UpdateInstanceTableRequest {
  description?: string(name='description'),
  fieldMap?: {
    fields?: [ 
      {
        defaultValue?: string(name='defaultValue'),
        description?: string(name='description'),
        isMultiValue?: boolean(name='isMultiValue'),
        isVirtual?: boolean(name='isVirtual'),
        onlineStatus?: boolean(name='onlineStatus'),
        pkey?: boolean(name='pkey'),
        pluginName?: string(name='pluginName'),
        pluginParam?: string(name='pluginParam'),
        seperator?: string(name='seperator'),
        sourceName?: string(name='sourceName'),
        sourceType?: string(name='sourceType'),
        targetName?: string(name='targetName'),
        targetType?: string(name='targetType'),
      }
    ](name='fields'),
    indexs?: [ 
      {
        field?: string(name='field'),
        indexName?: string(name='indexName'),
      }
    ](name='indexs'),
    isAttributePack?: boolean(name='isAttributePack'),
    maxSkeyNum?: long(name='maxSkeyNum'),
    offlineBuildProtectionThreshold?: long(name='offlineBuildProtectionThreshold'),
    pkey?: string(name='pkey'),
    recordType?: string(name='recordType'),
  }(name='fieldMap'),
  fullDataSourceConfig?: {
    odpsDataDesc?: {
      project?: string(name='project'),
      table?: string(name='table'),
    }(name='odpsDataDesc'),
    type?: string(name='type'),
  }(name='fullDataSourceConfig'),
  incDataSourceConfig?: {
    swiftDataDesc?: {
      topic?: string(name='topic'),
    }(name='swiftDataDesc'),
    type?: string(name='type'),
  }(name='incDataSourceConfig'),
  indexType?: string(name='indexType'),
  triggerMode?: string(name='triggerMode'),
  ttl?: long(name='ttl'),
}

model UpdateInstanceTableResponseBody = {
  code?: string(name='code'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  result?: map[string]any(name='result'),
}

model UpdateInstanceTableResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UpdateInstanceTableResponseBody(name='body'),
}

async function updateInstanceTable(instanceId: string, tableName: string, request: UpdateInstanceTableRequest): UpdateInstanceTableResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return updateInstanceTableWithOptions(instanceId, tableName, request, headers, runtime);
}

async function updateInstanceTableWithOptions(instanceId: string, tableName: string, request: UpdateInstanceTableRequest, headers: map[string]string, runtime: Util.RuntimeOptions): UpdateInstanceTableResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.description)) {
    body['description'] = request.description;
  }
  if (!Util.isUnset(request.fieldMap)) {
    body['fieldMap'] = request.fieldMap;
  }
  if (!Util.isUnset(request.fullDataSourceConfig)) {
    body['fullDataSourceConfig'] = request.fullDataSourceConfig;
  }
  if (!Util.isUnset(request.incDataSourceConfig)) {
    body['incDataSourceConfig'] = request.incDataSourceConfig;
  }
  if (!Util.isUnset(request.indexType)) {
    body['indexType'] = request.indexType;
  }
  if (!Util.isUnset(request.triggerMode)) {
    body['triggerMode'] = request.triggerMode;
  }
  if (!Util.isUnset(request.ttl)) {
    body['ttl'] = request.ttl;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'UpdateInstanceTable',
    version = '2021-12-30',
    protocol = 'HTTPS',
    pathname = `/api/v1/instances/${OpenApiUtil.getEncodeParam(instanceId)}/tables/${OpenApiUtil.getEncodeParam(tableName)}`,
    method = 'PUT',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

